// 
//  JKLrcLineModel.m
//  QQMusic
// 
//  Created by albert on 16/4/9.
//  Copyright (c) 2016年 albert. All rights reserved.
// 

#import "JKLrcLineModel.h"

@implementation JKLrcLineModel

- (instancetype)initWithLrcLineString:(NSString *)lrcLineString{
    if (self = [super init]) {
        // [01:05.43]我想就这样牵着你的手不放开
        NSArray *lrcArray = [lrcLineString componentsSeparatedByString:@"]"];
        
        NSString *timeString = [lrcArray.firstObject substringFromIndex:1];
        self.time = [self timeStringWithString:timeString];
        self.text = lrcArray.lastObject;
    }
    return self;
}

+ (instancetype)lrcLineWithLrcLineString:(NSString *)lrcLineString{
    return [[self alloc] initWithLrcLineString:lrcLineString];
}

#pragma mark - 将字符串转为时间
- (NSTimeInterval)timeStringWithString:(NSString *)timeString{
    // 01:05.43
    NSInteger min = [[[timeString componentsSeparatedByString:@":"] firstObject] integerValue];
    NSInteger second = [[timeString substringWithRange:NSMakeRange(3, 2)] integerValue];
    
    NSInteger msec = [[[timeString componentsSeparatedByString:@"."] lastObject] integerValue];
    
    return (min * 60 + second + msec * 0.01);
}
@end
